package com.seven.z7.logviewer.utilities;

import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.UIManager;

/**
 * A few utilities that simplify using windows in Swing. 1998-99 Marty Hall, http://www.apl.jhu.edu/~hall/java/
 */

public final class WindowUtilities {

    private WindowUtilities() {

    }

    /**
     * Tell system to use native look and feel, as in previous releases. Metal (Java) LAF is the default otherwise.
     */
    public static void setNativeLookAndFeel() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
            System.out.println("Error setting native LAF: " + e);
        }
    }

    public static void setJavaLookAndFeel() {
        try {
            UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
        } catch (Exception e) {
            System.out.println("Error setting Java LAF: " + e);
        }
    }

    public static void setMotifLookAndFeel() {
        try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
        } catch (Exception e) {
            System.out.println("Error setting Motif LAF: " + e);
        }
    }

    /**
     * A simplified way to see a JPanel or other Container. Pops up a JFrame with specified Container as the content
     * pane.
     */

    public static JFrame createFrame(Container c, Dimension dim, String title, Color color) {
        JFrame frame = new JFrame(title);
        frame.setBackground(color);
        c.setBackground(color);
        frame.setSize(dim);
        frame.setContentPane(c);
        frame.addWindowListener(new ExitListener());
        return frame;
    }

    /** Uses Color.white as the background color. */

    public static JFrame createFrame(Container c, Dimension dim, String title) {
        return createFrame(c, dim, title, Color.white);
    }

    /**
     * Uses Color.white as the background color, and the name of the Container's class as the JFrame title.
     */

    public static JFrame createFrame(Container content, Dimension dim) {
        return createFrame(content, dim, content.getClass().getName(), Color.white);
    }

    public static void showInfo(Container content, String title, String msg) {
        JOptionPane.showMessageDialog(content, msg, title, JOptionPane.INFORMATION_MESSAGE);
    }

    public static void showError(Container content, String title, String msg) {
        JOptionPane.showMessageDialog(content, msg, title, JOptionPane.ERROR_MESSAGE);
    }

    public static void showWarning(Container content, String title, String msg) {
        JOptionPane.showMessageDialog(content, msg, title, JOptionPane.WARNING_MESSAGE);
    }
}
